package com.cssw.fyzb.web.controller;

import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.web.dto.UserDto;
import com.cssw.fyzb.web.service.UserService;
import com.cssw.fyzb.web.util.SplitUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.cssw.fyzb.web.util.SplitUtil.splitToLongList;


/**
 * @Auther: zzf
 * @Date: 2020/12/2 11:20
 * @Description:
 */

@ApiModel("用户相关接口")
@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户列表", response = AjaxPage.class)
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "userId", value = "用户标识", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "userName", value = "用户名称", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "nickName", value = "昵称", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "supUserName", value = "推荐人", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "mobile", value = "手机号码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "supUserId", value = "手机号码", paramType = "query", dataType = "string", required = true),
    })
    public AjaxPage list(int page, int limit,Long userId, String userName, String nickName, String supUserName, String mobile,Long supUserId) {
        Map param = new HashMap();
        param.put("userId", userId);
        param.put("userName", userName);
        param.put("nickName", nickName);
        param.put("supUserName", supUserName);
        param.put("mobile", mobile);
        param.put("supUserId",supUserId);
        return userService.list(page, limit, param);
    }

    @ApiOperation(value = "用户详情", response = AjaxPage.class)
    @RequestMapping(value = "/getDetails", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户标识", paramType = "query", dataType = "string", required = true),
    })
    public AjaxData getDetails(String userId) {

        return userService.getDetails(userId);
    }

    @ApiOperation(value = "启用", response = AjaxData.class)
    @PostMapping(value = "/start")
    public AjaxData start(@RequestBody UserDto dto, BindingResult result) {
        return userService.start(dto.getUserId());
    }

    @ApiOperation(value = "冻结", response = AjaxData.class)
    @PostMapping(value = "/stop")
    public AjaxData stop(@RequestBody UserDto dto, BindingResult result) {
        return userService.stop(dto.getUserId());
    }
}
